const { exec } = require('../db/index')
// 查 增 改 删
const getList = async () => {
  const sql = `select * from users`;
  return await exec(sql)
}

const addItem = async ({ username, password, realname }) => {
  const sql = `insert into users (username, password, realname) 
  values ('${username}', '${password}', '${realname}');`
  return await exec(sql)
}

// 更新数据和删除数据是需要条件的 where id
const updateItem = async ({ updateId,  username, password, realname }) => {
  let sql = `update users set username='${username}', 
            password='${password}',
            realname='${realname}' 
            where id = ${updateId};`
    return await exec(sql)
}

const deleteItem = async (id) => {
  const sql = `delete from users where id = ${id};`
  return await exec(sql)
}

module.exports = {
  getList,
  addItem,
  updateItem,
  deleteItem
}